//
//  MTInfoUploadAuthVideoCell.swift
//  MT
//
//  Created by 陈悦 on 2020/5/16.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTInfoUploadAuthVideoCell: BaseMTInfoVerificationCell {
    
    var assetImage: UIImage? {
        didSet {
            guard let asset = assetImage else { return }
            selfVideo.image = asset
            selfVideo.contentMode = .scaleAspectFit
        }
    }
    
    lazy var selfVideo: UIImageView = {
        let imageview = UIImageView()
        imageview.image = UIImage(named: "add-vedio")
        imageview.backgroundColor = UIColor(hex:0xf8f8f8)
        imageview.layer.borderColor = UIColor(hex:0xd8d8d8).cgColor
        imageview.layer.borderWidth = 1
        imageview.isUserInteractionEnabled = true
        imageview.contentMode = .center
        let tap = UITapGestureRecognizer(target: self, action: #selector(infoUploadVideoCell(didTapUploadImage:)))
        imageview.addGestureRecognizer(tap)
        return imageview
    }()
    
    lazy var subTitleLab: UILabel = {
        let label = UILabel()
        label.font = PingFangSCSemiboldFont(16)
        label.textColor = UIColor.text.x1d1a1a
        label.text = "请进行视频审核"
        return label
    }()
    
    lazy var descLab: UILabel = {
        let label = UILabel()
        label.font = PingFangSCRegularFont(10)
        label.textColor = UIColor.text.x9b9b9b
        label.numberOfLines = 2
        label.text = "觅颜是一个100%全真人的社交平台\n所有人都需要经过视频视镜"
        return label
    }()
    
    lazy var tipsLab: UILabel = {
        let label = UILabel()
        label.font = PingFangSCRegularFont(10)
        label.textColor = UIColor.text.x9b9b9b
        label.text = "请自拍读出验证码，视频仅供内部视镜使用"
        return label
    }()
    
    lazy var startButton: UIButton = {
        let button = UIButton()
        button.setTitle("开始自拍视镜", for: .normal)
        button.setTitleColor(UIColor(hex: 0x1d1a1a), for: .normal)
        button.titleLabel?.font = PingFangSCSemiboldFont(14)
        button.layer.cornerRadius = 4
        button.backgroundColor = UIColor.theme.main
        return button
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initializeUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

// MARK: ------------------ 初始化 ----------------------
extension MTInfoUploadAuthVideoCell {
    
    override func prepareForReuse() {
        super.prepareForReuse()
        titleLabel.textColor = UIColor(hex: 0x1d1a1a)
        titleLabel.font = PingFangSCSemiboldFont(14)
        underline.backgroundColor = UIColor(hex:0xe6e6e6)
    }
    
    private func initializeUI() {
        contentView.addSubview(selfVideo)
        contentView.addSubview(subTitleLab)
        contentView.addSubview(descLab)
        contentView.addSubview(tipsLab)
        contentView.addSubview(startButton)
        textField.isHidden = true
        
        
        subTitleLab.snp.makeConstraints { (make) in
            make.centerY.equalTo(titleLabel)
            make.left.equalTo(130)
        }
        
        descLab.snp.makeConstraints { (make) in
            make.left.equalTo(subTitleLab)
            make.top.equalTo(subTitleLab.snp.bottom).offset(10)
        }
        
        
        selfVideo.snp.makeConstraints { (make) in
            make.left.equalTo(subTitleLab)
            make.top.equalTo(descLab.snp.bottom).offset(10)
            make.width.height.equalTo(165)
        }
        
        startButton.snp.makeConstraints { (make) in
            make.left.right.equalTo(selfVideo)
            make.top.equalTo(selfVideo.snp.bottom).offset(10)
            make.height.equalTo(30)
        }
        
        tipsLab.snp.makeConstraints { (make) in
            make.top.equalTo(startButton.snp.bottom).offset(10)
            make.left.equalTo(selfVideo)
        }
    
    }
    
}

extension MTInfoUploadAuthVideoCell {
    @objc private func infoUploadVideoCell(didTapUploadImage tap: UITapGestureRecognizer) {
        NotificationCenter.default.post(name: GlobalNotificationName.authVideo.name, object: nil)
    }
}

